<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
    <div class="container mt10">
      <el-card shadow="never" :body-style="{ padding: '10px 10px 5px' }" style="margin-right: 10px">
        <div slot="header" class="mb9 f16">
          <span style="font-weight: 600">选择指令</span>
        </div>
        <Table
          :tableData="tableData"
          :tableHeader="tableHeader"
          :TableHeight="100"
          :outTableHeight="70"
          :summaryData="summaryData"
          summary
          @currentRow="currentRow"
          :isLoading="isLoading"
        />
        <PageModule
          :PageData="{ total, pageSizeShow: true, buttonS: true }"
          :layout="'prev, pager'"
          @pageSizeChange="handleSizeChange"
          @pageChange="handleCurrentChange"
        />
      </el-card>

      <el-card shadow="never" :body-style="{ padding: '10px 10px 5px' }" style="margin-right: 10px">
        <div slot="header" class="mb9 f16">
          <span style="font-weight: 600">号码明细</span>
        </div>
        <Table :tableData="tableData2" :tableHeader="tableHeader2" :TableHeight="100" :outTableHeight="40" :summaryData="summaryData2" summary />
      </el-card>

      <el-card shadow="always" :body-style="{ padding: '0px' }" style="margin-right: 10px">
        <el-card shadow="never" :body-style="{ padding: '10px 10px 10px' }">
          <div slot="header" class="mb9 f16">
            <span style="font-weight: 600">指令投料明细</span>
          </div>
          <Table :tableData="tableData3" :tableHeader="tableHeader3" :TableHeight="50" :outTableHeight="80" :summaryData="summaryData3" summary />
        </el-card>

        <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
          <div slot="header" class="mb9 f16">
            <span style="font-weight: 600">指令已产明细</span>
          </div>
          <Table :tableData="tableData4" :tableHeader="tableHeader4" :TableHeight="50" :outTableHeight="80" :summaryData="summaryData4" summary />
        </el-card>
      </el-card>

      <el-card shadow="never" :body-style="{ padding: '0px' }">
        <el-card shadow="never" :body-style="{ padding: '10px 10px 10px' }">
          <div slot="header" class="mb9 f16">
            <span style="font-weight: 600">成型投料明细</span>
          </div>
          <Table
            :tableData="tableData5"
            :tableHeader="tableHeader5"
            :TableHeight="50"
            :outTableHeight="205"
            :summaryData="summaryData5"
            summary
            :isLoading="isLoading5"
          />
          <PageModule
            :PageData="{ total: total2, pageSizeShow: true, buttonS: true }"
            :layout="'prev, pager'"
            @pageSizeChange="handleSizeChange2"
            @pageChange="handleCurrentChange2"
          />
        </el-card>
        <el-card shadow="never" :body-style="{ padding: '10px 10px 0px' }">
          <div slot="header" class="mb9 f16">
            <span style="font-weight: 600">成型产出明细</span>
          </div>
          <Table
            :tableData="tableData6"
            :tableHeader="tableHeader6"
            :TableHeight="50"
            :outTableHeight="205"
            :summaryData="summaryData6"
            summary
            :isLoading="isLoading6"
          />
          <PageModule
            :PageData="{ total: total3, pageSizeShow: true, buttonS: true }"
            :layout="'prev, pager'"
            @pageSizeChange="handleSizeChange3"
            @pageChange="handleCurrentChange3"
          />
        </el-card>

        <PageModule :PageData="{ pageSizeShow: true }" class="mr10" />
      </el-card>
    </div>
  </div>
</template>
<script lang="ts">
import service from '@/utils/request'
import { ElMessage } from 'element-plus'
import { defineComponent, onMounted, ref, watch } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'MoldingProductionPueryKa'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },

  {
    type: 'select',
    selectValue: '',
    selectLabel: '部门',
    selectOptions: []
  },
  {
    type: 'date',
    dateLabel: '日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出成型生产状况'
  },
  {
    type: 'button',
    checkboxLabel: '导出RFT日报表'
  },
  {
    type: 'button',
    checkboxLabel: '导出月统计表'
  },
  {
    type: 'button',
    checkboxLabel: '导出日报表'
  },
  {
    type: 'button',
    checkboxLabel: '导出月报表'
  },
  {
    type: 'button',
    checkboxLabel: '导出品质报表'
  },
  {
    type: 'button',
    checkboxLabel: '查询成型投料/产出'
  }
])
// 表一模块
// '置空'按钮
const findClicked = (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  getTableList()
}
const tableHeader = ref([
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    label: '型体',
    prop: 'style'
  },
  {
    label: '颜色',
    prop: 'color'
  },
  {
    label: '订单量',
    prop: 'orders',
    width: 50
  },
  {
    label: '未投数量',
    prop: 'dosage'
  },
  {
    label: '未产数量',
    prop: 'production'
  }
])
const tableData = ref([])
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 4,
    num: 0
  },
  {
    index: 5,
    num: 0
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
const isLoading = ref(true)
// 获取表数据
const getTableList = async () => {
  let tableDataList = await service.post<any, any>('/production/getFormingProduction', {
    lotNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令'
    )?.inputValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value,
    style: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
    )?.inputValue
  })
  isLoading.value = false
  tableData.value = tableDataList.details
  total.value = tableDataList.total
  currentRow()
  summaryData.value[0].num = tableDataList.count.orderCount
  summaryData.value[1].num = tableDataList.count.surplusCount
}
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)

const summaryData2 = ref<summaryDataType[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  },
  {
    index: 3,
    num: 0
  },
  {
    index: 4,
    num: 0
  },
  {
    index: 5,
    num: 0
  },
  {
    index: 6,
    num: 0
  }
])
const summaryData3 = ref<summaryDataType[]>([
  {
    index: 2,
    num: 0
  }
])
const summaryData4 = ref<summaryDataType[]>([
  {
    index: 2,
    num: 0
  }
])

const tableHeader2 = ref([
  {
    label: '号码',
    prop: 'sizeNo',
    width: 55
  },
  {
    label: '订单数量',
    prop: 'orderNum',
    width: 55
  },
  {
    label: '已投数量',
    prop: 'submittedNum',
    width: 55
  },
  {
    label: '未投数量',
    prop: 'submittedNotNum',
    width: 55
  },
  {
    label: '已产数量',
    prop: 'producedNum',
    width: 55
  },
  {
    label: '未产数量',
    prop: 'producedNotNum',
    width: 55
  },
  {
    label: '在制数量',
    prop: 'productionNum',
    width: 55
  }
])
const tableData2 = ref([])
// 点击表给另一张表传数据
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}) => {
  let { lotNo }: any = row
  // 给表二传指令号
  let table2Data = await service.get<any, any>(`/production/getNumberDetail`, {
    params: {
      lotNo
    }
  })
  summaryData2.value[0].num = table2Data.count.orderNumCount
  summaryData2.value[1].num = table2Data.count.submittedNumCount
  summaryData2.value[2].num = table2Data.count.submittedNotNumCount
  summaryData2.value[3].num = table2Data.count.producedNumCount
  summaryData2.value[4].num = table2Data.count.producedNotNumCount
  summaryData2.value[5].num = table2Data.count.productionNumCount
  tableData2.value = table2Data.numberDetails
  // 给表三传指令号
  let table3Data = await service.get<any, any>(`/production/getThrowDetail`, {
    params: {
      lotNo
    }
  })
  summaryData3.value[0].num = table3Data.ThrowCount
  tableData3.value = table3Data.ThrowDetails

  // 给表四传指令号
  let table4Data = await service.get<any, any>(`/production/getProductionDetail`, {
    params: {
      lotNo
    }
  })
  summaryData4.value[0].num = table4Data.ProductionCount
  tableData4.value = table4Data.ProductionDetails
}

const tableHeader3 = ref([
  {
    label: '部门',
    prop: 'line'
  },
  {
    label: '投料日期',
    prop: 'collectTime'
  },
  {
    label: '投料数量',
    prop: 'qty'
  }
])
const tableData3 = ref([])

const tableHeader4 = ref([
  {
    label: '部门',
    prop: 'line'
  },
  {
    label: '已产日期',
    prop: 'collectTime'
  },
  {
    label: '已产数量',
    prop: 'qty'
  }
])
const tableData4 = ref([])

// 成型投料明细
const tableHeader5 = ref([
  {
    label: '部门',
    prop: 'line',
    width: '95px'
  },
  {
    label: '指令',
    prop: 'lotNo',
    width: '95px'
  },
  {
    label: '投料日期',
    prop: 'collectTime',
    width: '95px'
  },
  {
    label: '订单数量',
    prop: 'orderNumCount',
    width: '95px'
  },
  {
    label: '当日投料量',
    prop: 'submittedNumCount',
    width: '95px'
  },
  {
    label: '累计投料量',
    prop: 'accumulate',
    width: '95px'
  },
  {
    label: '未投数量',
    prop: 'submittedNotNumCount',
    width: '95px'
  }
])
const tableData5 = ref([])
// 分页器
const currentPage2 = ref(1)
const pageSize2 = ref(40)
const total2 = ref(0)
const handleSizeChange2 = (val: number) => {
  pageSize2.value = val
  getTableList2()
}
const handleCurrentChange2 = (val: number) => {
  currentPage2.value = val
  getTableList2()
}
// 获取表数据
const summaryData5 = ref<summaryDataType[]>([
  {
    index: 4,
    num: 0
  }
])
const isLoading5 = ref(true)
const getTableList2 = async () => {
  let tableDataList = await service.post<any, any>('/production/getFeedingDetails', {
    endTime: formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '日期')
      ?.dateValue?.[1],
    line: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '部门')
      ?.selectValue,
    startTime: formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '日期')
      ?.dateValue?.[0],
    pageNum: currentPage2.value,
    pageSize: pageSize2.value
  })
  isLoading5.value = false
  tableData5.value = tableDataList.feedingDetails.list
  total2.value = tableDataList.feedingDetails.total
  // currentRow()
  summaryData5.value[0].num = tableDataList.todayFeedingCount
}
onMounted(() => {
  getTableList2()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList2()
  }
)

const tableHeader6 = ref([
  {
    label: '部门',
    prop: 'line',
    width: '95px'
  },
  {
    label: '指令',
    prop: 'lotNo',
    width: '95px'
  },
  {
    label: '投料日期',
    prop: 'collectTime',
    width: '95px'
  },
  {
    label: '订单数量',
    prop: 'orderNumCount',
    width: '95px'
  },
  {
    label: '当日产出量',
    prop: 'submittedNumCount',
    width: '95px'
  },
  {
    label: '累计产出量',
    prop: 'accumulate',
    width: '95px'
  },
  {
    label: '未产数量',
    prop: 'submittedNotNumCount',
    width: '95px'
  }
])
const tableData6 = ref([])
// 分页器
const currentPage3 = ref(1)
const pageSize3 = ref(40)
const total3 = ref(0)
const handleSizeChange3 = (val: number) => {
  pageSize3.value = val
  getTableList2()
}
const handleCurrentChange3 = (val: number) => {
  currentPage3.value = val
  getTableList2()
}
// 获取表数据
const summaryData6 = ref<summaryDataType[]>([
  {
    index: 4,
    num: 0
  }
])
const isLoading6 = ref(true)
const getTableList3 = async () => {
  let tableDataList = await service.post<any, any>('/production/getOutputDetails', {
    endTime: formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '日期')
      ?.dateValue?.[1],
    line: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '部门')
      ?.selectValue,
    startTime: formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '日期')
      ?.dateValue?.[0],
    pageNum: currentPage3.value,
    pageSize: pageSize3.value
  })
  isLoading6.value = false
  tableData6.value = tableDataList.OutputDetailsList.list
  total3.value = tableDataList.OutputDetailsList.total
  // currentRow()
  summaryData6.value[0].num = tableDataList.todayOutputCount
}
onMounted(() => {
  getTableList3()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList3()
  }
)
</script>

<style lang="less" scoped>
.container {
  display: flex;
}

table {
  table-layout: auto !important;
}

:deep(.el-table__header) {
  width: 100% !important;
}

:deep(.el-table__body) {
  width: 100% !important;
}
</style>
